/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events;

import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.GUIDStorage;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

/**
 * @author Massimo Canonaco
 *
 */
public class FinalMovementEventInformation implements GenericEvent {

	static public final float GUID = GUIDStorage.FINAL_MOVEMENT_EVENT_INFORMATION;
	
	private int startingColumn;
	private int startingRow;
	private int endingRow;
	private int endingColumn;
	
	public FinalMovementEventInformation(int startingRow, int startingColumn, int endingRow, int endingColum) 
	{
		this.startingRow = startingRow;
		this.startingColumn = startingColumn;
		this.endingRow = endingRow;
		this.endingColumn = endingColum;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getGUID()
	 */
	@Override
	public float getGUID() 
	{
		return GUID;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getName()
	 */
	@Override
	public String getName() 
	{
		return "finalmovement";
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getAsJSONObject()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public JSONObject getAsJSONObject() 
	{
		JSONObject object = new JSONObject();
		object.put(GenericEvent.GLOBAL_GUID_KEY, getGUID());
		
		JSONArray positionArray = new JSONArray();
		positionArray.add(startingRow);
		positionArray.add(startingColumn);
		positionArray.add(endingRow);
		positionArray.add(endingColumn);
		
		object.put(POSITIONS, positionArray);
		
		return object;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#setFromJSONOnbject(org.json.simple.JSONObject)
	 */
	@Override
	public void setFromJSONOnbject(JSONObject object) 
	{
		JSONArray positionArray = (JSONArray)object.get(POSITIONS);
		
		startingRow = ((Long)positionArray.get(0)).intValue();
		startingColumn = ((Long)positionArray.get(1)).intValue();
		endingRow = ((Long)positionArray.get(2)).intValue();
		endingColumn = ((Long)positionArray.get(3)).intValue();
	}

	static private final String POSITIONS = "positions";

	/**
	 * @return the startingColumn
	 */
	public int getStartingColumn() {
		return startingColumn;
	}

	/**
	 * @return the startingRow
	 */
	public int getStartingRow() {
		return startingRow;
	}

	/**
	 * @return the endingRow
	 */
	public int getEndingRow() {
		return endingRow;
	}

	/**
	 * @return the endingColumn
	 */
	public int getEndingColumn() {
		return endingColumn;
	}
}
